package plg.grupo1.Lexico.StateMachineHierarchy;

import plg.grupo1.Lexico.reserveWords.NoExisteSimbolo;
import plg.grupo1.Lexico.reserveWords.SimboloNoTieneValorNumerico;
import plg.grupo1.Lexico.reserveWords.ValorFueraRango;

public class State12 implements State{
	
    private static State12 INSTANCE = null;    
	private State12(){}
	
    private synchronized static void createInstance() {
        if (INSTANCE == null) INSTANCE = new State12();
    }
    
    public static State12 getInstance() {
        if (INSTANCE == null) createInstance();
        return INSTANCE;
    }
    
	public void goNext(){
		
		if(Contexto.isEof()){
			Contexto.genErrorAndGoToInitialState("EOF","Character");
		}
		else{
			
			char c = Contexto.getCharAndMoveToNext();//A
	
			if(Character.isDigit(c)){
				Contexto.appendToControlWordNum(c);//
			}
			else if(c == ' '){
				//check control word
				try{
					Contexto.checkControlWord(Contexto.getLexema());
					Contexto.setCurrentState(State7.getInstance());
				}catch(NoExisteSimbolo e){
					Contexto.genErrorAndGoToInitialState("","Símbolo valido");
				}catch(SimboloNoTieneValorNumerico e){
					Contexto.genErrorAndGoToInitialState("","Símbolo sin valor numerico valido");
				}catch(ValorFueraRango e){
					Contexto.genErrorAndGoToInitialState("","Símbolo con valor numerico valido");
				}				
			}
			else if(c == ';')  {
				//Contexto.appendToLexema(c);//B
				Contexto.appendToControlWordDelim(c);//
				Contexto.setCurrentState(State10.getInstance());}
			else if(Contexto.isEscape(c)) 
				Contexto.setCurrentState(State20.getInstance());
			else{
				Contexto.genErrorAndGoToInitialState(Character.toString(c),"NUMERO || SEPARADOR");
			}
		}
	}
}